﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using ReallyReallyReallySimpleRoguelike.Managers;

namespace ReallyReallyReallySimpleRoguelike.Entities
{
    public class Player : Creature
    {
        public Player(Point p)
        {
            ImageCharacter = Constants.PlayerImage;
            Color = Constants.PlayerColor;
            Inventory = new List<Sword>();
            X = p.X;
            Y = p.Y;
            Hits = Constants.StartingHitPoints;
        }

        // This should be two separate methods.  Add one to the tile.
        //Refactor 6: Encapsulate the move action within the player class 
        public Boolean MovePlayer(Constants.Direction direction,int distance = 1)
        {
            //check for valid move
            for (int i = distance; i > 0; i--)
            {
                Point newPosition = GetNewPosition(direction, i);
                if (DungeonManager.Instance.DungeonLevel.IsOKToMove(newPosition))
                {
                    X = newPosition.X;
                    Y = newPosition.Y;
                    return true;
                }
            }
            return false;
        }

        private Point GetNewPosition(Constants.Direction direction, int distance)
        {
            Point newPoint = new Point(X, Y);
            switch (direction)
            {
                case Constants.Direction.N:
                    newPoint.Y -= distance;
                    break;
                case Constants.Direction.S:
                    newPoint.Y += distance;
                    break;
                case Constants.Direction.E:
                    newPoint.X += distance;
                    break;
                case Constants.Direction.W:
                    newPoint.X -= distance;
                    break;
            }
            return newPoint;
        }

        public IList<Sword> Inventory { get; set; }

    }
}
